<template>
  <div class="managelogin">
    <div class="logo">
      <img src="/static/images/logo.png" alt="三维影像报告查询系统">
    </div>
    <el-form label-position="left" label-width="50px" class="baseForm" :model="baseForm" @submit.native.prevent>
      <div class="formBox">
        <el-form-item label="账号">
          <el-input v-model.trim="baseForm.account" placeholder="请输入登录账号"></el-input>
          <!-- <el-input class="out" type="text"></el-input> -->
        </el-form-item>
        <el-form-item label="密码">
          <!-- <el-input show-password class="out" type="text"></el-input> -->
          <el-input show-password v-model.trim="baseForm.password" placeholder="请输入登录密码"></el-input>
        </el-form-item>
      </div>
      <div class="btns">
          <el-button class="btn" type="primary" native-type="submit" @click="goForm">账号登录</el-button>
          <el-button class="btn" type="danger" native-type="submit" @click="goFormNoLogin" v-if="isShow">影像查询</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import {login} from '@/depends/api/user'
import {mapMutations} from "vuex";

import {setStorage, getStorage} from '@/utils/tools/tools'

export default {
  components: {
  },
  data() {
    return {
      baseForm: {
        account: '',
        password: ''
      },
      isShow:false
    };
  },
  computed:{

  },
  created () {
    if (process.env.VUE_APP_NODE_ENV == 'dev') {
      // test管理
      // this.baseForm.account = 'admin'
      // this.baseForm.password = 'admin'

      // dev管理
      this.baseForm.account = 'admin'
      this.baseForm.password = 'qqqq1111'
      // dev医生
      // this.baseForm.account = 'mawentao'
      // this.baseForm.password = '123456'
    }
    if(this.$route.query && this.$route.query.id){
      this.isShow = true;
    }
  },
  mounted() {
    //this.judgeUrlLocation('http://192.168.10.17:8081/enquiry/modelreports/66');
  },
  methods:{
    ...mapMutations('user', ['SET_USER','OUT_SYS']),
    judgeUrlLocation(str){
      if(str !==''){
        let reg = /(\d+)$/g
        let result = reg.exec(str);
        if(result){ //如果没有匹配到，则result为null
          var matchNum = result[1];//结果数组中角标为1的值就是我们捕获的正则小分组中的串
          console.log(matchNum);
        }
        return result ==null ? null : matchNum;
      }
    },
    //医生管理员登录
    goForm () {
     // let result = this.judgeUrlLocation(this.$route.path);
      if (!this.baseForm.account) { this.$message.error('账号不能为空!'); return }
      if (!this.baseForm.password) { this.$message.error('密码不能为空!'); return }
      login(this.baseForm).then(res => {
        if (res.data.status != 200) {return}
        this.SET_USER(res.data.data)
        if(this.$route.query && this.$route.query.id){
          // this.$router.push({path:`/enquiry/modelreports/${this.$route.query.id}`});
          this.$router.replace({name: 'modelreports', params: {id: this.$route.query.id}})
        }else{
          this.$router.replace({name: 'patientManage'})
        }

      })

    },
    //访客登录
    goFormNoLogin(){
     // let result = this.judgeUrlLocation(this.$route.path); //eg : '/index?id=66'
      if(this.$route.query && this.$route.query.id){
        this.OUT_SYS();
        // this.$router.push({path:`/enquiry/modelreports/${this.$route.query.id}`});
          this.$router.replace({name: 'modelreports', params: {id: this.$route.query.id}})
      }else{
        this.$message.warning('请输入用户名密码登录');
      }
    }
  },
  beforeDestroy() {
  },
}
</script>
<style scoped lang="less">
.managelogin {
  max-width: 450px;
  margin: 0 auto;
  padding: 0 40px;
  height: 100%;
  padding-top: 200px;
  .logo {
    text-align: center;
    img {
      max-width: 100%;
    }
    .z {
      font-size: 36px;
      font-weight: bold;
    }
    .e {
      font-size: 16px;
    }
  }
  .btns {
    margin-top: 30px;
    display: flex;
    .btn {
      flex: 1;
    }
  }
  .baseForm {
    margin-top: 30px;
    border-top: 1px solid #eee;
    .formBox {
      padding: 15px 0;
      border-bottom: 1px solid #eee;
    }
    .el-form-item:last-child {
      margin-bottom: 0;
    }
    input:-webkit-autofill {
      -webkit-text-fill-color: #000 !important;
      transition: background-color 5000s ease-in-out 0s;
    }
  }
}
</style>
